package com.tn.openrpc.stomp;

import java.text.MessageFormat;

import com.tn.openrpc.util.Factory;
import com.tn.openrpc.util.FactoryException;

/**
 * An implementation of <code>Factory</code> that creates a name for a temporary queue (in Active MQ when using STOMP).
 */
public class TemporaryQueueNameFactory implements Factory<String>
{
  private static final MessageFormat QUEUE_NAME = new MessageFormat("/temp-queue/{0}");

  private Factory<String> idFactory;

  /**
   * Creates a new <code>TemporaryQueueNameFactory</code> initialized with the <code>idFactory</code> used to ensure the queue name is
   * unique.
   */
  public TemporaryQueueNameFactory(Factory<String> idFactory)
  {
    this.idFactory = idFactory;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String newInstance() throws FactoryException
  {
    return QUEUE_NAME.format(new Object[]{idFactory.newInstance()});
  }
}
